package com.zzl.study.aj.controller;

import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: zhangzl
 * @date: 2024/5/6 10:55
 * @version: 1.0
 * @description: 后端二次校验接口示例
 */
@Slf4j
@RestController
@RequestMapping("/auth")
public class LoginController {

    @Autowired
    private CaptchaService captchaService;

    @PostMapping("/login")
    public ResponseModel get(@RequestParam("captchaVerification") String captchaVerification) {
        CaptchaVO captchaVO = new CaptchaVO();
        captchaVO.setCaptchaVerification(captchaVerification);
        ResponseModel response = captchaService.verification(captchaVO);
        if (!response.isSuccess()) {
            //验证码校验失败，返回信息告诉前端
            switch (response.getRepCode()) {
                case "9999" -> log.error("服务器内部异常");
                case "0011" -> log.error("参数不能为空");
                case "6110" -> log.error("验证码已失效，请重新获取");
                case "6111" -> log.error("验证失败");
                case "6112" -> log.error("获取验证码失败,请联系管理员");
                default -> log.error("服务器内部异常");
            }
        } else {
            //repCode  0000  无异常，代表成功
            log.info("无异常，代表成功");
        }
        return response;
    }


}
